#pragma once
#include "../EventManager/interfaces.h"
#include <boost\thread\mutex.hpp>
#include "ThreadSafeQueue.h"
#include <Windows.h>

namespace re{
	namespace real{

//-----------------------------------------------------------------------------------------------------------
//Realtime Listener. Listening for events from the event manager(between threads)
//-----------------------------------------------------------------------------------------------------------

typedef ThreadSafeQueue<EventDataPtr> EventDataQueue;
class RealtimeListener : public IEventListener
{
public:
	RealtimeListener() {}
	~RealtimeListener() {}

	EventDataQueue m_queue;
	virtual void VHandleEvent(EventDataPtr data);
};
//-----------------------------------------------------------------------------------------------------------
//Realtime Process. Manages the thread and keeping it alive inside
//-----------------------------------------------------------------------------------------------------------
class RealtimeProcess
{
public:
	RealtimeProcess() : m_thread_created(false) { }
	~RealtimeProcess() { if(m_thread_created) KillProcess(); }

private:
	static DWORD WINAPI BeginThread(LPVOID lParam);

	HANDLE m_Thread;
	bool   m_is_running;
	bool   m_thread_created;
	mutable boost::mutex m_mutex;
	RealtimeListener* m_listener;
public:
	void LaunchProcess();
	void StartProcess();
	void PauseProcess();
	void KillProcess();
private:
	void Run();

	virtual void VUpdate() = 0;
	virtual void VResumed() = 0;
	virtual void VPaused() = 0;
};

}
}